//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "AliMikhailHaqCopula.h"
using namespace Cephei::QL::Math::Copulas;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (Double theta) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phAliMikhailHaqCopula = NULL;
#endif
        QuantLib::Real _theta = (QuantLib::Real)ValueHelper::Convert (theta); //d
        _ppAliMikhailHaqCopula = new boost::shared_ptr<QuantLib::AliMikhailHaqCopula> (new QuantLib::AliMikhailHaqCopula ( _theta ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (boost::shared_ptr<QuantLib::AliMikhailHaqCopula>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAliMikhailHaqCopula = NULL;
#endif
	_ppAliMikhailHaqCopula = &childNative;
    
}
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (QuantLib::AliMikhailHaqCopula& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phAliMikhailHaqCopula = NULL;
#endif
	_ppAliMikhailHaqCopula = new boost::shared_ptr<QuantLib::AliMikhailHaqCopula> (&childNative);
    
    _AliMikhailHaqCopulaOwner = owner;
    
}

Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (CAliMikhailHaqCopula^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAliMikhailHaqCopula = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppAliMikhailHaqCopula = new boost::shared_ptr<QuantLib::AliMikhailHaqCopula> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAliMikhailHaqCopula = NULL;
#endif
	if (!t->IsSubclassOf(CAliMikhailHaqCopula::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (QuantLib::Handle<QuantLib::AliMikhailHaqCopula>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phAliMikhailHaqCopula = &childNative;
	_ppAliMikhailHaqCopula = &static_cast<boost::shared_ptr<QuantLib::AliMikhailHaqCopula>>(childNative.currentLink());
    
    _AliMikhailHaqCopulaOwner = owner;
}
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (QuantLib::Handle<QuantLib::AliMikhailHaqCopula> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phAliMikhailHaqCopula = &childNative;
	_ppAliMikhailHaqCopula = &static_cast<boost::shared_ptr<QuantLib::AliMikhailHaqCopula>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::CAliMikhailHaqCopula (QuantLib::AliMikhailHaqCopula childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAliMikhailHaqCopula = NULL;
#endif
	_ppAliMikhailHaqCopula = new boost::shared_ptr<QuantLib::AliMikhailHaqCopula> (new QuantLib::AliMikhailHaqCopula (childNative));
    
}
#endif

Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::~CAliMikhailHaqCopula ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppAliMikhailHaqCopula != NULL)
    {
	    delete _ppAliMikhailHaqCopula;
        _ppAliMikhailHaqCopula = NULL;
    }
}
Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::!CAliMikhailHaqCopula ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppAliMikhailHaqCopula != NULL)
    {
	    delete _ppAliMikhailHaqCopula;
    }
}
QuantLib::AliMikhailHaqCopula& Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::GetReference ()
{
    if (_ppAliMikhailHaqCopula == NULL) throw REFNEW NativeNullException ();
	return **_ppAliMikhailHaqCopula;
}
boost::shared_ptr<QuantLib::AliMikhailHaqCopula>& Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::GetShared ()
{
    if (_ppAliMikhailHaqCopula == NULL) throw REFNEW NativeNullException ();
	return *_ppAliMikhailHaqCopula;
}
QuantLib::AliMikhailHaqCopula* Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::GetPointer ()
{
    if (_ppAliMikhailHaqCopula == NULL) throw REFNEW NativeNullException ();
	return &**_ppAliMikhailHaqCopula;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::AliMikhailHaqCopula>& Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::GetHandle ()
{
	if (_phAliMikhailHaqCopula == NULL)
	{
		_phAliMikhailHaqCopula = new Handle<QuantLib::AliMikhailHaqCopula> (*_ppAliMikhailHaqCopula);
	}
	return *_phAliMikhailHaqCopula;
}
#endif
bool Cephei::QL::Math::Copulas::CAliMikhailHaqCopula::HasNative () 
{
	return (_ppAliMikhailHaqCopula != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Copulas::IAliMikhailHaqCopula^ Cephei::QL::Math::Copulas::CAliMikhailHaqCopula_Factory::Create (Double theta)
{
    return REFNEW CAliMikhailHaqCopula ( theta);
}
